package com.example.springbootsfzy.controller.sunnan;

import com.example.springbootsfzy.domain.PsychologicalQaQuestions;
import com.example.springbootsfzy.service.sunnan.PsychologicalQaQuestionsService;
import com.example.springbootsfzy.util.R;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/psychologicalQaQuestions")
public class PsychologicalQaQuestionsController {
    @Autowired
    private PsychologicalQaQuestionsService psychologicalQaQuestionsService;


    /**
     * 根据id查找问题
     */
    @GetMapping("{questionId}")
    @ResponseBody
    public PsychologicalQaQuestions selectById(@PathVariable int questionId) {
        return psychologicalQaQuestionsService.selectQuestionById(questionId);
    }

    /**
     * 根据发布时间分页查询心理测评问题
     * @param pageNum 当前页码
     * @param pageSize 每页显示的数量
     * @return PageInfo
     */
    @GetMapping("/q")
    @ResponseBody
    public PageInfo<PsychologicalQaQuestions> selectPaginatedQuestionsByQ(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "5") int pageSize) {
        return psychologicalQaQuestionsService.selectPaginatedQuestionsByQ(pageNum, pageSize);
    }

    /**
     * 根据回复时间分页查询心理测评问题
     * @param pageNum 当前页码
     * @param pageSize 每页显示的数量
     * @return PageInfo
     */
    @GetMapping("/r")
    @ResponseBody
    public PageInfo<PsychologicalQaQuestions> selectPaginatedQuestionsByR(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "5") int pageSize) {
        return psychologicalQaQuestionsService.selectPaginatedQuestionsByR(pageNum, pageSize);
    }

    /**
     * 根据回复数量分页查询心理测评问题
     * @param pageNum 当前页码
     * @param pageSize 每页显示的数量
     * @return PageInfo
     */
    @GetMapping("/t")
    @ResponseBody
    public PageInfo<PsychologicalQaQuestions> selectPaginatedQuestionsByT(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "5") int pageSize) {
        return psychologicalQaQuestionsService.selectPaginatedQuestionsByT(pageNum, pageSize);
    }

    /**
     * 添加心理测评问题
     * @param psychologicalQaQuestions 心理测评问题对象
     */
    @PostMapping
    @ResponseBody
    public R addPsychologicalQaQuestions(@RequestBody PsychologicalQaQuestions psychologicalQaQuestions) {
        if (psychologicalQaQuestionsService.addPsychologicalQaQuestions(psychologicalQaQuestions) > 0) {
            return R.ok(null);
        } else {
            return R.fail("添加失败");
        }
    }
    /**
     * 根据id删除心理测评问题
     * @param id 心理测评问题id
     */
    @DeleteMapping("/{id}")
    public R deleteById(@PathVariable int id) {
        if (psychologicalQaQuestionsService.deletePsychologicalQaQuestions(id) > 0) {
            return R.ok(null);
        } else {
            return R.fail("删除失败");
        }
    }
    /**
     * 修改心理测评问题
     * @param psychologicalQaQuestions 心理测评问题对象
     */

    @PutMapping
    @ResponseBody
    public R updatePsychologicalQaQuestions(@RequestBody PsychologicalQaQuestions psychologicalQaQuestions) {
        if (psychologicalQaQuestionsService.updatePsychologicalQaQuestions(psychologicalQaQuestions) > 0) {
            return R.ok(null);
        } else {
            return R.fail("修改失败");
        }
    }


}

